package io.jft.doll.adapter

import android.support.v4.view.PagerAdapter
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import io.jft.doll.model.bindModel.ImageBind

/**
 * Created by G on 2017/8/16 0016.
 */

class ImageSliderPageAdapter : PagerAdapter() {
    private var images: ArrayList<ImageBind> = ArrayList()

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        //绑定src
        images[position].bind()
        //添加到视图
        val image = getImage(position)
        container.addView(image)
        return image!!
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeView(getImage(position))
    }

    override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj
    override fun getCount(): Int = images.size
    private fun getImage(position: Int): ImageView? = images[position].getImageView()

    fun setImageViewList(arrayList: ArrayList<ImageBind>) {
        this.images = arrayList
        notifyDataSetChanged()
    }
}